"use client";

import { useEffect, useState } from "react";
import { Header } from "@/components/header";
import "./globals.css";

export default function RootLayout({ children }) {
  const [mounted, setMounted] = useState(false);

  // 确保只在客户端渲染时应用主题
  useEffect(() => {
    setMounted(true);
    // 检查本地存储中的主题设置
    const savedTheme = localStorage.getItem("theme");
    const prefersDark = window.matchMedia(
      "(prefers-color-scheme: dark)"
    ).matches;

    if (savedTheme === "dark" || (!savedTheme && prefersDark)) {
      document.documentElement.classList.add("dark");
    } else {
      document.documentElement.classList.remove("dark");
    }
  }, []);

  return (
    <html lang='zh-CN' suppressHydrationWarning>
      {/* <head>
        <title>雅典娜知识库</title>
        <meta name='description' content='企业知识管理系统' />
      </head> */}
      <body className='min-h-screen transition-colors duration-300'>
        <Header />
        <main className='w-full'>{children}</main>
      </body>
    </html>
  );
}
